package com.example.firstproject.service;

import com.example.firstproject.entity.User;
import com.example.firstproject.entity.XuanKe;
import com.example.firstproject.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class UserService<allUser> {

    @Autowired
    private UserMapper userMapper;
    private String allUser;
    private  String username;

    public Map<String, Object> userRegist(User user) {
        User userOld = UserMapper.getByStudentIdOrName(user.getStudentId(), user.getUsername());
        Map<String, Object> retData = new HashMap<>();
        if (userOld != null) {
            retData.put("code", 500);
            retData.put("message", "用户名或密码重复");
        } else {
            userMapper.insertUser(user);
            retData.put("code", 200);
            retData.put("message", "注册成功!");
        }
        return retData;
    }

    public Map<String, Object> userLogin(User user) {
        User user1 = userMapper.getAllUser(user.getUsername());
        Map<String,Object> retData = new HashMap<>();
        if (user1 != null) {
            retData.put("code",500);
            retData.put("message","error");
        } else {
            retData.put("code", 200);
            retData.put("message", "成功!");

        }
        return retData;
    }


    public List<User> getAllUser() {
        List<User> users = userMapper.getUser(new HashMap<>());
        return users;
    }
}